package com.datang.pet.common.utils;

//import com.google.gson.Gson;
import com.alibaba.fastjson.JSON;
import com.datang.pet.common.properties.WxAK;

import java.util.HashMap;
import java.util.Map;

/**
 * 访问互联网工具类
 */
public class AccessNetwork {
    //异常写入日志
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AccessNetwork.class);
    /**
     * 获取微信用户的openId
     */
    public String getUserOpenId(String jsCode){
        Map<String, String> params=new HashMap<String , String>();
        params.put("appid", WxAK.APPID);
        params.put("secret",WxAK.SECRET);
        params.put("js_code",jsCode);
        params.put("grant_type","authorization_code");
        String httpResult=null;
        String url = WxAK.URL;
        try{
            httpResult=HttpUtils.get(url,params);
            Map<String,String> maps = (Map) JSON.parse(httpResult);
            String openId=maps.get("openid");
            return openId;
        }catch (Exception e){
            log.error("获取openID出错了");
            return "err";
        }


    }

}
